<template>
    <div class="login">
        <div class="e-mail">
            <span><img src="@/assets/email.png" /></span><input type="text" v-model="email" placeholder="请输入邮箱" />
        </div>
        <div class="password">
            <span><img src="@/assets/password.png" /></span><input type="password" v-model="pwd" placeholder="请输入密码" />
        </div>
        <button @click="login">登录</button>
    </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { myLogin } from "../../request/index.js";
import { showToast } from "vant";
let router = useRouter();
let email = ref("");
let pwd = ref("");
let login = () => {
    let user_acc = email.value;
    let user_pwd = pwd.value;
    if (user_acc.length == 0 || user_pwd == 0) {
        showToast("内容不能为空");
        return;
    }
    myLogin({ user_acc, user_pwd })
        .then((content) => {
            let { token, code, msg } = content;
            // console.log(content);
            if (code == 200) {
                showToast(msg);
                localStorage.setItem("my_token", token);
                router.push({ path: "/myindex/mypage" });
            } else {
                showToast(msg);
            }
        })
        .catch((err) => {
            showToast(err);
        });
};
</script>

<style lang="scss">
.login {
    .password {
        input {
            width: 100%;
        }
    }
    .code {
        color: #828282;
        border: 1px solid #ccc;
        box-sizing: border-box;
        padding: 0.1875rem;
        height: 1.875rem;
        display: flex;
        flex: 1;
        font-size: 13px;
        border-radius: 1rem;
        justify-content: center;
        align-items: center;
    }
    div {
        width: 100%;
        height: 3.125rem;
        border-bottom: 1px solid #dedede;
        display: flex;
        align-items: center;
        span {
            img {
                height: 1.5625rem;
            }
        }
    }
    input {
        font-size: 15px;
        height: 2.5rem;
        padding-left: 0.625rem;
        color: #828282;
    }
    input::placeholder {
        color: #b5b5b5;
    }
    button {
        font-size: 1rem;
        margin-top: 1.25rem;
        color: #fff;
        background-color: #ff9092;
        width: 100%;
        height: 2.5rem;
        border-radius: 1rem;
    }
}
</style>
